#!/bin/bash

# 版本兼容性检查脚本
# 检查Spring Boot、Spring Cloud、Spring Cloud Alibaba版本兼容性

echo "=== Spring Cloud Alibaba 版本兼容性检查 ==="
echo

# 读取pom.xml中的版本信息
SPRING_BOOT_VERSION=$(grep -A 1 "<spring-boot.version>" pom.xml | tail -1 | sed 's/.*>\(.*\)<.*/\1/')
SPRING_CLOUD_VERSION=$(grep -A 1 "<spring-cloud.version>" pom.xml | tail -1 | sed 's/.*>\(.*\)<.*/\1/')
SPRING_CLOUD_ALIBABA_VERSION=$(grep -A 1 "<spring-cloud-alibaba.version>" pom.xml | tail -1 | sed 's/.*>\(.*\)<.*/\1/')

echo "当前版本配置:"
echo "  Spring Boot: $SPRING_BOOT_VERSION"
echo "  Spring Cloud: $SPRING_CLOUD_VERSION"
echo "  Spring Cloud Alibaba: $SPRING_CLOUD_ALIBABA_VERSION"
echo

# 版本兼容性矩阵
echo "推荐版本组合:"
echo "┌─────────────┬──────────────┬─────────────────────┐"
echo "│ Spring Boot │ Spring Cloud │ Spring Cloud Alibaba│"
echo "├─────────────┼──────────────┼─────────────────────┤"
echo "│ 3.1.5       │ 2022.0.4     │ 2022.0.0.0          │"
echo "│ 3.0.6       │ 2022.0.3     │ 2022.0.0.0          │"
echo "│ 2.7.18      │ 2021.0.8     │ 2021.0.5.0          │"
echo "└─────────────┴──────────────┴─────────────────────┘"
echo

# 检查当前版本是否在推荐列表中
if [[ "$SPRING_BOOT_VERSION" == "3.1.5" && "$SPRING_CLOUD_VERSION" == "2022.0.4" && "$SPRING_CLOUD_ALIBABA_VERSION" == "2022.0.0.0" ]]; then
    echo "✅ 版本组合兼容 - 推荐使用"
elif [[ "$SPRING_BOOT_VERSION" == "3.0.6" && "$SPRING_CLOUD_VERSION" == "2022.0.3" && "$SPRING_CLOUD_ALIBABA_VERSION" == "2022.0.0.0" ]]; then
    echo "✅ 版本组合兼容 - 推荐使用"
elif [[ "$SPRING_BOOT_VERSION" == "2.7.18" && "$SPRING_CLOUD_VERSION" == "2021.0.8" && "$SPRING_CLOUD_ALIBABA_VERSION" == "2021.0.5.0" ]]; then
    echo "✅ 版本组合兼容 - 推荐使用"
else
    echo "⚠️  版本组合可能不兼容"
    echo "   建议使用推荐的版本组合以避免兼容性问题"
fi

echo
echo "=== 检查完成 ==="
